<nz-divider></nz-divider>
<nz-breadcrumb>
  <nz-breadcrumb-item>
    <a [routerLink]="['/']">
      <i nz-icon nzType="home"></i>
      <span>{{ 'menu.dashboard' | i18n }}</span>
    </a>
  </nz-breadcrumb-item>
  <nz-breadcrumb-item>
    <i nz-icon nzType="monitor"></i>
    <span>{{ 'monitor.app.' + app | i18n }} {{ 'monitors.list' | i18n }}</span>
  </nz-breadcrumb-item>
</nz-breadcrumb>
<nz-divider></nz-divider>

<div>
  <button nz-button nzType="primary" (click)="sync()" nz-tooltip [nzTooltipTitle]="'common.refresh' | i18n">
    <i nz-icon nzType="sync" nzTheme="outline"></i>
  </button>
  <button nz-button nzType="primary">
    <a routerLink="/monitors/new" [queryParams]="{ app: app }">
      <i nz-icon nzType="appstore-add" nzTheme="outline"></i>
      {{ 'monitors.new' | i18n }} {{ 'monitor.app.' + app | i18n }}
    </a>
  </button>

  <button nz-button nzType="primary" (click)="onEnableManageMonitors()">
    <i nz-icon nzType="up-circle" nzTheme="outline"></i>
    {{ 'monitors.enable' | i18n }}
  </button>
  <button nz-button nzType="primary" nzDanger (click)="onCancelManageMonitors()">
    <i nz-icon nzType="down-circle" nzTheme="outline"></i>
    {{ 'monitors.cancel' | i18n }}
  </button>
  <button nz-button nzType="primary" nzDanger (click)="onDeleteMonitors()">
    <i nz-icon nzType="delete" nzTheme="outline"></i>
    {{ 'monitors.delete' | i18n }}
  </button>

  <button style="margin-right: 25px; float: right" nz-button nzType="primary" (click)="onFilterSearchMonitors()">
    {{ 'common.search' | i18n }}
  </button>
  <input
    style="margin-right: 5px; float: right; width: 150px; border-radius: 9px; text-align: center"
    nz-input
    type="text"
    [placeholder]="'monitors.search.placeholder' | i18n"
    nzSize="default"
    (keyup.enter)="onFilterSearchMonitors()"
    [(ngModel)]="filterContent"
  />
  <nz-select
    style="margin-right: 10px; float: right; width: 120px"
    nzAllowClear
    [nzPlaceHolder]="'monitors.search.filter' | i18n"
    [(ngModel)]="filterStatus"
  >
    <nz-option [nzLabel]="'monitor.status.all' | i18n" nzValue="9"></nz-option>
    <nz-option [nzLabel]="'monitor.status.available' | i18n" nzValue="1"></nz-option>
    <nz-option [nzLabel]="'monitor.status.unavailable' | i18n" nzValue="2"></nz-option>
    <nz-option [nzLabel]="'monitor.status.unreachable' | i18n" nzValue="3"></nz-option>
    <nz-option [nzLabel]="'monitor.status.un-manage' | i18n" nzValue="0"></nz-option>
  </nz-select>
</div>

<nz-table
  #fixedTable
  [nzData]="monitors"
  [nzPageIndex]="pageIndex"
  [nzPageSize]="pageSize"
  [nzTotal]="total"
  nzFrontPagination="false"
  [nzLoading]="tableLoading"
  nzShowSizeChanger
  [nzShowTotal]="rangeTemplate"
  [nzPageSizeOptions]="[8, 15, 25]"
  (nzQueryParams)="onTablePageChange($event)"
  nzShowPagination="true"
  [nzScroll]="{ x: '1150px', y: '1240px' }"
>
  <thead>
    <tr>
      <th nzAlign="center" nzLeft nzWidth="4%" [(nzChecked)]="checkedAll" (nzCheckedChange)="onAllChecked($event)"></th>
      <th nzAlign="center" nzLeft>{{ 'monitor.name' | i18n }}</th>
      <th nzAlign="center">{{ 'monitor.status' | i18n }}</th>
      <th nzAlign="center">{{ 'monitor.host' | i18n }}</th>
      <th nzAlign="center">{{ 'monitor.app' | i18n }}</th>
      <th nzAlign="center">{{ 'common.edit-time' | i18n }}</th>
      <th nzAlign="center">{{ 'common.edit' | i18n }}</th>
    </tr>
  </thead>
  <tbody>
    <tr *ngFor="let data of fixedTable.data">
      <td nzAlign="center" nzLeft [nzChecked]="checkedMonitorIds.has(data.id)" (nzCheckedChange)="onItemChecked(data.id, $event)"></td>
      <td nzAlign="center" nzLeft>
        <a [routerLink]="['/monitors/' + data.id]">
          <span>{{ data.name }}</span>
        </a>
      </td>
      <td nzAlign="center">
        <nz-tag *ngIf="data.status == 0" nzColor="default">
          <i nz-icon nzType="robot" nzTheme="outline"></i>
          <span>{{ 'monitor.status.un-manage' | i18n }}</span>
        </nz-tag>
        <nz-tag *ngIf="data.status == 1" nzColor="success">
          <i nz-icon nzType="smile" nzTheme="outline"></i>
          <span>{{ 'monitor.status.available' | i18n }}</span>
        </nz-tag>
        <nz-tag *ngIf="data.status == 2" nzColor="warning">
          <i nz-icon nzType="meh" nzTheme="outline"></i>
          <span>{{ 'monitor.status.unavailable' | i18n }}</span>
        </nz-tag>
        <nz-tag *ngIf="data.status == 3" nzColor="error">
          <i nz-icon nzType="frown" nzTheme="outline"></i>
          <span>{{ 'monitor.status.unreachable' | i18n }}</span>
        </nz-tag>
      </td>
      <td nzAlign="center">{{ data.host }}</td>
      <td nzAlign="center">
        <nz-tag nzColor="processing">
          <i nz-icon nzType="cloud"></i>
          <span>{{ 'monitor.app.' + data.app | i18n }}</span>
        </nz-tag>
      </td>
      <td nzAlign="center">{{ (data.gmtUpdate ? data.gmtUpdate : data.gmtCreate) | date: 'YYYY-MM-dd HH:mm:ss' }}</td>
      <td nzAlign="center">
        <button nz-button nzType="primary" (click)="onEditOneMonitor(data.id)" nz-tooltip [nzTooltipTitle]="'monitors.edit-monitor' | i18n">
          <i nz-icon nzType="edit" nzTheme="outline"></i>
        </button>
        <button
          nz-button
          nzType="primary"
          (click)="onEnableManageOneMonitor(data.id)"
          nz-tooltip
          [nzTooltipTitle]="'monitors.enable' | i18n"
        >
          <i nz-icon nzType="up-circle" nzTheme="outline"></i>
        </button>
        <button
          nz-button
          nzDanger
          nzType="primary"
          (click)="onCancelManageOneMonitor(data.id)"
          nz-tooltip
          [nzTooltipTitle]="'monitors.cancel' | i18n"
        >
          <i nz-icon nzType="down-circle" nzTheme="outline"></i>
        </button>
        <button
          nz-button
          nzDanger
          nzType="primary"
          (click)="onDeleteOneMonitor(data.id)"
          nz-tooltip
          [nzTooltipTitle]="'monitors.delete-monitor' | i18n"
        >
          <i nz-icon nzType="delete" nzTheme="outline"></i>
        </button>
      </td>
    </tr>
  </tbody>
</nz-table>

<ng-template #rangeTemplate> {{ 'common.total' | i18n }} {{ total }} </ng-template>
